Using fields that bind to data sources only at runtime
The RDC now enables you to create report templates based on unbound field objects. Then, using minimal code, you can bind field objects to a data source (or one of several data sources) at runtime. The Report Engine uses the data type and the Name property of the unbound field object to match it with a data field in the recordset.
This functionality makes it easy to build reporting into n-tier applications where you have on-demand recordsets and non-continuous data connections. It also makes it easy to build a single report that can work with a variety of recordsets, making development and maintenance more efficient.
To take advantage of this functionality:
- Add the RDC to your project. For further information, see Adding the RDC to your project.
- Choose the Unbound Fields option from the Field Explorer in the RDC.
- Choose a field object by data type and drag it into position where you want it to appear on your report.
- Set the Name property of the field object to match the name of the field in your recordset that you want it to bind to.
- Continue until you have all your fields in place.
- Write the code to activate the binding. This code example binds to a database table.
In the code, set up an Object variable for your report. For example:
Dim Report As New CrystalReport1
- Then to create the binding, code using the new Report object method AutoSetUnboundFieldSource:
Report.AutoSetUnboundFieldSource crBMTName